
package com.zs.record;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.czt.mp3recorder.MP3Recorder;
import com.zs.record.utils.MediaPlayUtil;

import java.io.File;
import java.io.IOException;

public class TestActivity extends Activity {

	private MP3Recorder mRecorder;
	private String mFilePath;
	private File mVoiceFile;
	private MediaPlayUtil mMediaPlayUtil;
	private String mFileName = "abc.amr";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_layout);
		Button startButton = (Button) findViewById(R.id.StartButton);
		mMediaPlayUtil = MediaPlayUtil.getInstance();
		initPlay();

		mRecorder = new MP3Recorder(mFilePath + mFileName);

		startButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				try {
					mRecorder.start();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		});
		Button stopButton = (Button) findViewById(R.id.StopButton);
		stopButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mRecorder.stop();
			}
		});
	}

	private void initPlay(){
		mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ABRecrodSounds/";
		mVoiceFile = new File(mFilePath);
		if (!mVoiceFile.exists()) {
			mVoiceFile.mkdirs();
		}
	}

	public void play(View view){
		mMediaPlayUtil.play(mFilePath + mFileName);
//		if (mVoiceFile.exists()){
//		}else{
//			Toast.makeText(this, "NO", Toast.LENGTH_SHORT).show();
//		}
	}


	@Override
	protected void onDestroy() {
		super.onDestroy();
		mRecorder.stop();
	}
}
